package app.sevenc.lib_framework.mvvm.v

import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import app.sevenc.lib_framework.BaseFrameApplication
import app.sevenc.lib_framework.R
import app.sevenc.lib_framework.permission.PermissionProxy
import com.blankj.utilcode.util.KeyboardUtils

/**
 * Fragment基类
 *
 * @author Seven-C
 * @date 2021/8/18
 */
abstract class BaseFrameFragment : Fragment() {

    protected val mFragmentProvider: ViewModelProvider by lazy { ViewModelProvider(this) }
    protected val mActivityProvider: ViewModelProvider by lazy { ViewModelProvider(this.requireActivity()) }


    override fun onPause() {
        super.onPause()
        //关闭软键盘
        KeyboardUtils.hideSoftInput(requireActivity())
    }

    /**
     * 权限请求
     *
     * @param permissions Array<out String>
     * @param action Function1<Boolean, Unit>
     */
    fun requestPermission(vararg permissions: String, action: (Boolean) -> Unit) {
        PermissionProxy.requestPermission(this, listOf(*permissions)) {
            action(it)
        }
    }
}